package com.zl.learning.object.clone;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class TestClone {
    public static void main(String[] args) {
//        User u = new User(1,"zhansan","111");
//        User u1 = u.clone();
//        System.out.println(u1.getId());
//        System.out.println(u == u1);

        User u = new User(1, "zhansan1", "111");
        User u2 = new User(2, "zhansan2", "112");
        User u3 = new User(3, "zhansan3", "113");

        List<User> userList = new ArrayList<>();
        userList.add(u);
        userList.add(u2);
        userList.add(u3);
        ClassRoom classRoom = new ClassRoom();
        classRoom.setId(1);
        classRoom.setUsers(userList);
        Gson g = new Gson();

//        ClassRoom c2 = classRoom.clone();
        ClassRoom c2 = g.fromJson(g.toJson(classRoom), ClassRoom.class);

        u3.setId(4);

        c2.setId(2);
        System.out.println(g.toJson(classRoom));
        System.out.println(g.toJson(c2));
    }
}
